<?php


namespace app\common\model;


use think\Db;
use think\Model;

class ApplyModel extends Model
{
    protected $name = 'apply';


    /**
     * 提交习题
     * @param int $user_id
     * @param $company_id
     * @param $company_position_id
     * @param $name
     * @param $mobile
     * @param $file
     * @param $sex
     * @param $date
     * @param $education
     * @return array
     */
    public function apply(int $user_id, $company_id, $company_position_id, $name, $mobile, $file, $sex, $date, $education): array
    {
        Db::startTrans();
        try {
            $this->create([
                'user_id' => $user_id,
                'company_id' => $company_id,
                'company_position_id' => $company_position_id,
                'name' => $name,
                'mobile' => $mobile,
                'file' => $file,
                'sex' => $sex,
                'date' => $date,
                'education' => $education,
                'createtime' => time(),
            ]);

            Db::commit();
            return [
                'code' => 200,
                'msg' => '请求成功',
                'data' => [],
            ];
        } catch (\Exception $e) {
            Db::rollback();
            return [
                'code' => $e->getCode(),
                'msg' => $e->getMessage(),
                'data' => []
            ];
        }
    }

}